/**
 * 
 */
package org.braketester.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.LinkedBlockingQueue;

import org.braketester.entry.ExceptionResolver;

/**
 * @author LAP
 *
 */
public class RawData implements Serializable{
	private static final long serialVersionUID = 7008533622560787406L;
	private String name;
	private Date date;
	private int channelsCount;
	private LinkedBlockingQueue<ArrayList<Double>> data;
	
	public RawData(int channelsCount) throws IllegalArgumentException {
		if (channelsCount > 8 || channelsCount <= 0) throw new IllegalArgumentException("Channels count must be between 8 and 0");
		name = "No name";
		date = new Date();
		data = new LinkedBlockingQueue<ArrayList<Double>>();
		this.channelsCount = channelsCount;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}
	/**
	 * @param date the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}
	
	public void addDataList(ArrayList<Double> list) {
		tryPutValues(list);
	}
	
	private void tryPutValues(ArrayList<Double> list) {
		try {
			data.put(list);
		} catch (InterruptedException e) {
			ExceptionResolver.getInstance().logException(e);
			ExceptionResolver.getInstance().showException(e);
		}
	}
	
	public ArrayList<Double> getLoaded() {
		return tryTakeValues();
	}
	
	private ArrayList<Double> tryTakeValues() {
		ArrayList<Double> ret = null;
		try {
			ret = data.take();
		} catch (InterruptedException e) {
			ExceptionResolver.getInstance().logException(e);
			ExceptionResolver.getInstance().showException(e);
		}
		return ret;
	}
	
	/**
	 * @return the channalsCount
	 */
	public int getChannalsCount() {
		return channelsCount;
	}
}
